// DlgPrintProcess.cpp : implementation file
//

#include "stdafx.h"
#include "Celsus.h"
#include "DlgPrintProcess.h"
#include "afxdialogex.h"


// CDlgPrintProcess dialog

IMPLEMENT_DYNAMIC(CDlgPrintProcess, CDialog)

CDlgPrintProcess::CDlgPrintProcess(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgPrintProcess::IDD, pParent)
	, m_szMessage(_T(""))
{
	m_nCount = -1;
	m_nLibraryID = -1;
}

CDlgPrintProcess::~CDlgPrintProcess()
{
}

void CDlgPrintProcess::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_STATIC_MESSAGE, m_szMessage);
	DDX_Control(pDX, IDC_COMBO_LIBRARY, m_ctrlLibrary);
}


BEGIN_MESSAGE_MAP(CDlgPrintProcess, CDialog)
	ON_BN_CLICKED(IDC_BUTTON_NO, &CDlgPrintProcess::OnBnClickedButtonNo)
END_MESSAGE_MAP()


// CDlgPrintProcess message handlers


BOOL CDlgPrintProcess::OnInitDialog()
{
	CDialog::OnInitDialog();

	ASSERT( m_nCount > 0 );
	ASSERT( m_nLibraryID > 0 );

	// get string arrays if needed
	if( m_szaLibrary.IsEmpty() )
		appConfig.m_SQL.GetDescriptions( CMySQLEx::library, &m_szaLibrary );

	INT nCurSel = 0;
	INT nSel = 0;
	CString szTemp;

	// set m_ctrlLibrary
	for( INT nIndex = 0; nIndex < m_szaLibrary.GetCount(); nIndex++ )
	{
		szTemp = m_szaLibrary.GetAt( nIndex );
		if( !szTemp.IsEmpty() )
		{
			nSel = m_ctrlLibrary.AddString( szTemp );
			m_ctrlLibrary.SetItemData( nSel, nIndex );
			if( m_nLibraryID == nIndex )
				nCurSel = nSel;
		}
	}
	m_ctrlLibrary.SetCurSel( nCurSel );

	// set message
	m_szMessage.Format( _T("Did you want to also send the %d selected request(s) to Processing?"), m_nCount );

	// update data
	UpdateData( FALSE );

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


void CDlgPrintProcess::OnOK()
{
	// get library id
	m_nLibraryID = m_ctrlLibrary.GetItemData( m_ctrlLibrary.GetCurSel() );
	if( m_nLibraryID < 0 )
		return;

	CDialog::OnOK();
}


void CDlgPrintProcess::OnCancel()
{
	// TODO: Add your specialized code here and/or call the base class

	CDialog::OnCancel();
}


void CDlgPrintProcess::OnBnClickedButtonNo()
{
	EndDialog( IDNO );
}
